<?php
/*
	This SQL query will create the table to store your object.

	CREATE TABLE `visit_tick` (
	`visit_tickid` int(11) NOT NULL auto_increment,
	`true_timestamp` INT NOT NULL,
	`hour_timestamp` INT NOT NULL,
	`day_timestamp` INT NOT NULL,
	`week_timestamp` INT NOT NULL,
	`month_timestamp` INT NOT NULL,
	`hour` TINYINT NOT NULL,
	`weekday` TINYINT NOT NULL,
	`monthday` TINYINT NOT NULL,
	`month` TINYINT NOT NULL, PRIMARY KEY  (`visit_tickid`)) ENGINE=MyISAM;
*/

/**
* <b>visit_tick</b> class with integrated CRUD methods.
* @author Php Object Generator
* @version POG 3.0f / PHP5
* @copyright Free for personal & commercial use. (Offered under the BSD license)
* @link http://www.phpobjectgenerator.com/?language=php5&wrapper=pog&objectName=visit_tick&attributeList=array+%28%0A++0+%3D%3E+%27true_timestamp%27%2C%0A++1+%3D%3E+%27hour_timestamp%27%2C%0A++2+%3D%3E+%27day_timestamp%27%2C%0A++3+%3D%3E+%27week_timestamp%27%2C%0A++4+%3D%3E+%27month_timestamp%27%2C%0A++5+%3D%3E+%27views_on_page_at_tick%27%2C%0A++6+%3D%3E+%27hour%27%2C%0A++7+%3D%3E+%27weekday%27%2C%0A++8+%3D%3E+%27monthday%27%2C%0A++9+%3D%3E+%27month%27%2C%0A%29&typeList=array+%28%0A++0+%3D%3E+%27INT%27%2C%0A++1+%3D%3E+%27INT%27%2C%0A++2+%3D%3E+%27INT%27%2C%0A++3+%3D%3E+%27INT%27%2C%0A++4+%3D%3E+%27INT%27%2C%0A++5+%3D%3E+%27HASMANY%27%2C%0A++6+%3D%3E+%27TINYINT%27%2C%0A++7+%3D%3E+%27TINYINT%27%2C%0A++8+%3D%3E+%27TINYINT%27%2C%0A++9+%3D%3E+%27TINYINT%27%2C%0A%29
*/
include_once('class.pog_base.php');
class visit_tick extends POG_Base
{
	public $visit_tickId = '';

	/**
	 * @var INT
	 */
	public $true_timestamp;
	
	/**
	 * @var INT
	 */
	public $hour_timestamp;
	
	/**
	 * @var INT
	 */
	public $day_timestamp;
	
	/**
	 * @var INT
	 */
	public $week_timestamp;
	
	/**
	 * @var INT
	 */
	public $month_timestamp;
	
	/**
	 * @var private array of views_on_page_at_tick objects
	 */
	private $_views_on_page_at_tickList = array();
	
	/**
	 * @var TINYINT
	 */
	public $hour;
	
	/**
	 * @var TINYINT
	 */
	public $weekday;
	
	/**
	 * @var TINYINT
	 */
	public $monthday;
	
	/**
	 * @var TINYINT
	 */
	public $month;
	
	public $pog_attribute_type = array(
		"visit_tickId" => array('db_attributes' => array("NUMERIC", "INT")),
		"true_timestamp" => array('db_attributes' => array("NUMERIC", "INT")),
		"hour_timestamp" => array('db_attributes' => array("NUMERIC", "INT")),
		"day_timestamp" => array('db_attributes' => array("NUMERIC", "INT")),
		"week_timestamp" => array('db_attributes' => array("NUMERIC", "INT")),
		"month_timestamp" => array('db_attributes' => array("NUMERIC", "INT")),
		"views_on_page_at_tick" => array('db_attributes' => array("OBJECT", "HASMANY")),
		"hour" => array('db_attributes' => array("NUMERIC", "TINYINT")),
		"weekday" => array('db_attributes' => array("NUMERIC", "TINYINT")),
		"monthday" => array('db_attributes' => array("NUMERIC", "TINYINT")),
		"month" => array('db_attributes' => array("NUMERIC", "TINYINT")),
		);
	public $pog_query;
	
	
	/**
	* Getter for some private attributes
	* @return mixed $attribute
	*/
	public function __get($attribute)
	{
		if (isset($this->{"_".$attribute}))
		{
			return $this->{"_".$attribute};
		}
		else
		{
			return false;
		}
	}
	
	function visit_tick($true_timestamp='', $hour_timestamp='', $day_timestamp='', $week_timestamp='', $month_timestamp='', $hour='', $weekday='', $monthday='', $month='')
	{
		$this->true_timestamp = $true_timestamp;
		$this->hour_timestamp = $hour_timestamp;
		$this->day_timestamp = $day_timestamp;
		$this->week_timestamp = $week_timestamp;
		$this->month_timestamp = $month_timestamp;
		$this->_views_on_page_at_tickList = array();
		$this->hour = $hour;
		$this->weekday = $weekday;
		$this->monthday = $monthday;
		$this->month = $month;
	}
	
	
	/**
	* Gets object from database
	* @param integer $visit_tickId 
	* @return object $visit_tick
	*/
	function Get($visit_tickId)
	{
		$connection = Database::Connect();
		$this->pog_query = "select * from `visit_tick` where `visit_tickid`='".intval($visit_tickId)."' LIMIT 1";
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$this->visit_tickId = $row['visit_tickid'];
			$this->true_timestamp = $this->Unescape($row['true_timestamp']);
			$this->hour_timestamp = $this->Unescape($row['hour_timestamp']);
			$this->day_timestamp = $this->Unescape($row['day_timestamp']);
			$this->week_timestamp = $this->Unescape($row['week_timestamp']);
			$this->month_timestamp = $this->Unescape($row['month_timestamp']);
			$this->hour = $this->Unescape($row['hour']);
			$this->weekday = $this->Unescape($row['weekday']);
			$this->monthday = $this->Unescape($row['monthday']);
			$this->month = $this->Unescape($row['month']);
		}
		return $this;
	}
	
	
	/**
	* Returns a sorted array of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param string $sortBy 
	* @param boolean $ascending 
	* @param int limit 
	* @return array $visit_tickList
	*/
	function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$connection = Database::Connect();
		$sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
		$this->pog_query = "select * from `visit_tick` ";
		$visit_tickList = Array();
		if (sizeof($fcv_array) > 0)
		{
			$this->pog_query .= " where ";
			for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
			{
				if (sizeof($fcv_array[$i]) == 1)
				{
					$this->pog_query .= " ".$fcv_array[$i][0]." ";
					continue;
				}
				else
				{
					if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
					{
						$this->pog_query .= " AND ";
					}
					if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
					{
						if ($GLOBALS['configuration']['db_encoding'] == 1)
						{
							$value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
							$this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
						}
						else
						{
							$value =  POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
							$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
						}
					}
					else
					{
						$value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
						$this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
					}
				}
			}
		}
		if ($sortBy != '')
		{
			if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
			{
				if ($GLOBALS['configuration']['db_encoding'] == 1)
				{
					$sortBy = "BASE64_DECODE($sortBy) ";
				}
				else
				{
					$sortBy = "$sortBy ";
				}
			}
			else
			{
				$sortBy = "$sortBy ";
			}
		}
		else
		{
			$sortBy = "visit_tickid";
		}
		$this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
		$thisObjectName = get_class($this);
		$cursor = Database::Reader($this->pog_query, $connection);
		while ($row = Database::Read($cursor))
		{
			$visit_tick = new $thisObjectName();
			$visit_tick->visit_tickId = $row['visit_tickid'];
			$visit_tick->true_timestamp = $this->Unescape($row['true_timestamp']);
			$visit_tick->hour_timestamp = $this->Unescape($row['hour_timestamp']);
			$visit_tick->day_timestamp = $this->Unescape($row['day_timestamp']);
			$visit_tick->week_timestamp = $this->Unescape($row['week_timestamp']);
			$visit_tick->month_timestamp = $this->Unescape($row['month_timestamp']);
			$visit_tick->hour = $this->Unescape($row['hour']);
			$visit_tick->weekday = $this->Unescape($row['weekday']);
			$visit_tick->monthday = $this->Unescape($row['monthday']);
			$visit_tick->month = $this->Unescape($row['month']);
			$visit_tickList[] = $visit_tick;
		}
		return $visit_tickList;
	}
	
	
	/**
	* Saves the object to the database
	* @return integer $visit_tickId
	*/
	function Save($deep = true)
	{
		$connection = Database::Connect();
		$this->pog_query = "select `visit_tickid` from `visit_tick` where `visit_tickid`='".$this->visit_tickId."' LIMIT 1";
		$rows = Database::Query($this->pog_query, $connection);
		if ($rows > 0)
		{
			$this->pog_query = "update `visit_tick` set 
			`true_timestamp`='".$this->Escape($this->true_timestamp)."', 
			`hour_timestamp`='".$this->Escape($this->hour_timestamp)."', 
			`day_timestamp`='".$this->Escape($this->day_timestamp)."', 
			`week_timestamp`='".$this->Escape($this->week_timestamp)."', 
			`month_timestamp`='".$this->Escape($this->month_timestamp)."', 
			`hour`='".$this->Escape($this->hour)."', 
			`weekday`='".$this->Escape($this->weekday)."', 
			`monthday`='".$this->Escape($this->monthday)."', 
			`month`='".$this->Escape($this->month)."' where `visit_tickid`='".$this->visit_tickId."'";
		}
		else
		{
			$this->pog_query = "insert into `visit_tick` (`true_timestamp`, `hour_timestamp`, `day_timestamp`, `week_timestamp`, `month_timestamp`, `hour`, `weekday`, `monthday`, `month` ) values (
			'".$this->Escape($this->true_timestamp)."', 
			'".$this->Escape($this->hour_timestamp)."', 
			'".$this->Escape($this->day_timestamp)."', 
			'".$this->Escape($this->week_timestamp)."', 
			'".$this->Escape($this->month_timestamp)."', 
			'".$this->Escape($this->hour)."', 
			'".$this->Escape($this->weekday)."', 
			'".$this->Escape($this->monthday)."', 
			'".$this->Escape($this->month)."' )";
		}
		$insertId = Database::InsertOrUpdate($this->pog_query, $connection);
		if ($this->visit_tickId == "")
		{
			$this->visit_tickId = $insertId;
		}
		if ($deep)
		{
			foreach ($this->_views_on_page_at_tickList as $views_on_page_at_tick)
			{
				$views_on_page_at_tick->visit_tickId = $this->visit_tickId;
				$views_on_page_at_tick->Save($deep);
			}
		}
		return $this->visit_tickId;
	}
	
	
	/**
	* Clones the object and saves it to the database
	* @return integer $visit_tickId
	*/
	function SaveNew($deep = false)
	{
		$this->visit_tickId = '';
		return $this->Save($deep);
	}
	
	
	/**
	* Deletes the object from the database
	* @return boolean
	*/
	function Delete($deep = false, $across = false)
	{
		if ($deep)
		{
			$views_on_page_at_tickList = $this->GetViews_on_page_at_tickList();
			foreach ($views_on_page_at_tickList as $views_on_page_at_tick)
			{
				$views_on_page_at_tick->Delete($deep, $across);
			}
		}
		$connection = Database::Connect();
		$this->pog_query = "delete from `visit_tick` where `visit_tickid`='".$this->visit_tickId."'";
		return Database::NonQuery($this->pog_query, $connection);
	}
	
	
	/**
	* Deletes a list of objects that match given conditions
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param bool $deep 
	* @return 
	*/
	function DeleteList($fcv_array, $deep = false, $across = false)
	{
		if (sizeof($fcv_array) > 0)
		{
			if ($deep || $across)
			{
				$objectList = $this->GetList($fcv_array);
				foreach ($objectList as $object)
				{
					$object->Delete($deep, $across);
				}
			}
			else
			{
				$connection = Database::Connect();
				$pog_query = "delete from `visit_tick` where ";
				for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
				{
					if (sizeof($fcv_array[$i]) == 1)
					{
						$pog_query .= " ".$fcv_array[$i][0]." ";
						continue;
					}
					else
					{
						if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
						{
							$pog_query .= " AND ";
						}
						if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
						{
							$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
						}
						else
						{
							$pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
						}
					}
				}
				return Database::NonQuery($pog_query, $connection);
			}
		}
	}
	
	
	/**
	* Gets a list of views_on_page_at_tick objects associated to this one
	* @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...} 
	* @param string $sortBy 
	* @param boolean $ascending 
	* @param int limit 
	* @return array of views_on_page_at_tick objects
	*/
	function GetViews_on_page_at_tickList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
	{
		$views_on_page_at_tick = new views_on_page_at_tick();
		$fcv_array[] = array("visit_tickId", "=", $this->visit_tickId);
		$dbObjects = $views_on_page_at_tick->GetList($fcv_array, $sortBy, $ascending, $limit);
		return $dbObjects;
	}
	
	
	/**
	* Makes this the parent of all views_on_page_at_tick objects in the views_on_page_at_tick List array. Any existing views_on_page_at_tick will become orphan(s)
	* @return null
	*/
	function SetViews_on_page_at_tickList(&$list)
	{
		$this->_views_on_page_at_tickList = array();
		$existingViews_on_page_at_tickList = $this->GetViews_on_page_at_tickList();
		foreach ($existingViews_on_page_at_tickList as $views_on_page_at_tick)
		{
			$views_on_page_at_tick->visit_tickId = '';
			$views_on_page_at_tick->Save(false);
		}
		$this->_views_on_page_at_tickList = $list;
	}
	
	
	/**
	* Associates the views_on_page_at_tick object to this one
	* @return 
	*/
	function AddViews_on_page_at_tick(&$views_on_page_at_tick)
	{
		$views_on_page_at_tick->visit_tickId = $this->visit_tickId;
		$found = false;
		foreach($this->_views_on_page_at_tickList as $views_on_page_at_tick2)
		{
			if ($views_on_page_at_tick->views_on_page_at_tickId > 0 && $views_on_page_at_tick->views_on_page_at_tickId == $views_on_page_at_tick2->views_on_page_at_tickId)
			{
				$found = true;
				break;
			}
		}
		if (!$found)
		{
			$this->_views_on_page_at_tickList[] = $views_on_page_at_tick;
		}
	}
}
?>